using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class GamePanel : BasePanel<GamePanel>
{
    //获取控件
    public MyGUILable labScore;
    public MyGUILable labTime;
    public MyGUIButton btnQuit;
    public MyGUIButton btnSetting;
    public MyGUITexture texHP;

    public float hpWidth = 400;
    //当前分数
    [HideInInspector]
    public int nowScore = 0;
    [HideInInspector]
    public float nowTime;
    private int time;
    private void Start()
    {
        btnSetting.onClick += () =>
        {
            SettingPanel.Instance.ShowPanel();
        };
        btnQuit.onClick += () => 
        { 
            QuitPanel.Instance.ShowPanel();
            Time.timeScale = 0;
        };
        //AddScore(50);
        //UpdateHP(100, 30);
    }
    private void Update()
    {
        nowTime += Time.deltaTime;
        labTime.content.text = "";
        time = (int)nowTime;
        if (time / 3600 > 0)
        {
            labTime.content.text += time / 3600 + "h";
        }
        if (time % 3600 / 60 > 0 || labTime.content.text != "")
        {
            labTime.content.text += time % 3600 / 60 + "m";
        }
        labTime.content.text += time % 60 + "s";
    }
    /// <summary>
    /// 更新分数
    /// </summary>
    /// <param name="score"></param>
    public void AddScore(int score)
    {
        nowScore += score;
        labScore.content.text = nowScore.ToString();
    }

    /// <summary>
    /// 更新血条
    /// </summary>
    /// <param name="maxHP"></param>
    /// <param name="HP"></param>
    public void UpdateHP(int maxHP, int HP)
    {
        texHP.guiPos.width = (float)HP / maxHP * hpWidth;
    }
}
